var t = getApp();

Page({
  data: {
    TypeName: "无",
    updateTime: "",
    // order: ""
    order:{
      payStatus:2,
      status:1,
      buyerRate:1,
      orderItems:[
        {
          id:1,
          itemId:1,
          picPath:'/assets/images/796.png',
          title:'维生素',
          price:3000,
          num:2
        },
        {
          id: 1,
          itemId: 1,
          picPath: '/assets/images/796.png',
          title: '维生素',
          price: 3000,
          num: 2
        },
        {
          id: 1,
          itemId: 1,
          picPath: '/assets/images/796.png',
          title: '维生素',
          price: 3000,
          num: 2
        },
        {
          id: 1,
          itemId: 1,
          picPath: '/assets/images/796.png',
          title: '维生素',
          price: 3000,
          num: 2,        
        }
      ],
      postFee:30,
      payment:10,
      returnPrice: 20,
      payment: 1000,
      orderId: 123456
    },
    updateTime:'2018-10-30',
    TypeName:'小花',
    actualPayment:1000,
    updateTime: '2017-10-30',
    num:4,
    status:3
  },
  onShareAppMessage: function(a) {
    return t.globalData.share;
  },
  onLoad: function(a) {
    // wx.showLoading({
    //     title: "加载中...",
    //     mask: !0
    // });
    // var e = this,
    //   o = a.orderId,
    //   n = this.data.TypeName,
    //   r = wx.getStorageSync("logs") || "";
    // r || (t.getToken(), r = wx.getStorageSync("logs")), this.setData({
    //   token: r,
    //   orderId: o
    // }), wx.request({
    //   url: t.globalData.httpOne + "mall/order/detail",
    //   data: {
    //     token: e.data.token,
    //     orderId: e.data.orderId
    //   },
    //   success: function(a) {
    //     if (200 == a.data.code) {
    //       console.log(a.data);
    //       var o = t.toDate(a.data.data.order.updateTime),
    //         r = a.data.data.order,
    //         d = ((r.payment + r.returnPrice - r.postFee) / 100).toFixed(2);
    //       r.payment = (r.payment / 100).toFixed(2), console.log(r.payment), r.postFee = (r.postFee / 100).toFixed(2),
    //         r.returnPrice = (r.returnPrice / 100).toFixed(2);
    //       var s = a.data.data.bill.billStatus,
    //         i = 0;
    //       r.orderItems.forEach(function(t, a) {
    //           i += t.num;
    //         }), 1 == s && (n = "个人/明细"), 2 == s && (n = "单位"), wx.setStorageSync("orderList", r),
    //         e.setData({
    //           addr: a.data.data.addr,
    //           updateTime: o,
    //           order: r,
    //           TypeName: n,
    //           num: i,
    //           actualPayment: d
    //         });
    //     }
    //   },
    //   fail: function() {
    //     wx.showToast({
    //       title: "系统繁忙，请稍后重试~",
    //       icon: "none",
    //       duration: 2e3
    //     });
    //   },
    //   complete: function() {
    //     wx.hideLoading();
    //   }
    // });
  },
  onShow: function() {},
  onHide: function() {},
  changeStatus: function() {
    var a = this;
    wx.showModal({
      title: "确认收货",
      content: "请确保您已收到商品",
      confirmColor: "#3b4ca9",
      success: function(e) {
        e.confirm && wx.request({
          url: t.globalData.httpOne + "mall/order/update",
          data: {
            token: a.data.token,
            orderId: a.data.orderId,
            status: 3,
            payStatus: 0
          },
          success: function(t) {
            200 == t.data.code && wx.showToast({
              title: "确认收货成功",
              icon: "success",
              duration: 2e3,
              success: function() {
                setTimeout(function(t) {
                  wx.navigateBack({
                    delta: 1
                  });
                }, 2e3);
              }
            });
          },
          fail: function() {
            wx.showToast({
              title: "系统繁忙，请稍后重试",
              icon: "none",
              duration: 2e3
            });
          }
        });
      }
    });
  },
  toPayFor: function(a) {
    var e = this,
      o = e.data.orderId;
    console.log(o);
    var n = e.data.order;
    console.log(n), n.createTime = t.toDate(n.updateTime), wx.showLoading({
      mask: !0
    }), wx.request({
      url: t.globalData.httpToPay,
      data: {
        orderId: o,
        token: e.data.token
      },
      success: function(t) {
        if (200 == t.data.code) {
          var a = t.data.data;
          console.log(a), wx.requestPayment({
            appId: a.appId,
            timeStamp: a.timeStamp,
            nonceStr: a.nonceStr,
            package: a.packageValue,
            signType: a.signType,
            paySign: a.paySign,
            success: function(t) {
              if (console.log(t), "requestPayment:ok" == t.errMsg) {
                try {
                  wx.setStorageSync("payList", n);
                } catch (t) {}
                wx.redirectTo({
                  url: "/pages/shopsub/pages/oss/oss?orderId=" + e.data.orderId
                });
              }
            },
            fail: function(t) {
              t.errMsg;
            },
            complete: function() {
              e.setData({
                payBoo: !0
              });
            }
          });
        }
      },
      fail: function() {
        wx.showToast({
          title: "系统繁忙，请稍后重试",
          icon: "none",
          duration: 2e3
        });
      },
      complete: function() {
        wx.hideLoading();
      }
    });
  },
  copy: function() {
    var t = this.data.order.orderId.toString();
    wx.setClipboardData({
      data: t,
      success: function(t) {
        wx.getClipboardData({
          success: function() {
            wx.showToast({
              title: "复制成功",
              icon: "none",
              duration: 2e3
            });
          }
        });
      }
    });
  }
});